//
//  DiTuXuanDianViewController.m
//  JuBoCRM
//
//  Created by iMac on 2024/2/3.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "DiTuXuanDianViewController.h"
//#import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件
//#import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
//
//#import <BMKLocationkit/BMKLocationComponent.h>
//
//#import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
//#import <BaiduMapAPI_Search/BMKGeocodeSearchOption.h>
//#import <BaiduMapAPI_Search/BMKGeocodeSearchResult.h>
//
//#import "MyAnnotation.h"
//#import "CustomPinAnnotationView.h"

#import "XuanZeDiDianTableViewCell.h"
@interface DiTuXuanDianViewController ()
//<BMKMapViewDelegate,BMKLocationAuthDelegate,BMKLocationManagerDelegate,BMKGeneralDelegate,BMKGeoCodeSearchDelegate>{
//    NSMutableArray *dataSource;
//    NSArray *orignArray;
//}
//
//@property (nonatomic,strong) BMKMapView *mapView;
//
//@property (nonatomic, strong) BMKLocationManager *locationManager; //当前位置对象
//@property (nonatomic, strong) BMKUserLocation *userLocation;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomSpace;

@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingTableView *mainTableView;
@property (nonatomic,strong) NSMutableArray *annotationArray;

//@property (nonatomic, strong) BMKGeoCodeSearch * geocodeSearch;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomViewHeight;
@property (weak, nonatomic) IBOutlet UITextField *searchTf;

@end

@implementation DiTuXuanDianViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.customNavBar.title = @"地图";
    
//    _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, NavaBarHeight, ScreenWidth, ScreenHeight-NavaBarHeight-328-ScreenBottom)];
//    _mapView.delegate = self;
//    [self.view insertSubview:_mapView atIndex:0];
//    
//    [_mapView setMapType:BMKMapTypeStandard];
//    
//    [[BMKLocationAuth sharedInstance] checkPermisionWithKey:@"fcTsq0s7sDHqH1Zs5QTLkvTGmpqmoDsR" authDelegate:self];
//    
//    _mapView.showsUserLocation = YES;
//    
//    _mapView.userTrackingMode = BMKUserTrackingModeFollow;
//    
//    
//    //初始化实例
//    _locationManager = [[BMKLocationManager alloc] init];
//    //设置delegate
//    _locationManager.delegate = self;
//    //设置返回位置的坐标系类型
//    _locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;
//    //设置距离过滤参数
//    _locationManager.distanceFilter = kCLDistanceFilterNone;
//    //设置预期精度参数
//    _locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
//    //设置应用位置类型
//    _locationManager.activityType = CLActivityTypeAutomotiveNavigation;
//    //设置是否自动停止位置更新
//    _locationManager.pausesLocationUpdatesAutomatically = NO;
//    //设置是否允许后台定位
//    //_locationManager.allowsBackgroundLocationUpdates = YES;
//    //设置位置获取超时时间
//    _locationManager.locationTimeout = 10;
//    //设置获取地址信息超时时间
//    _locationManager.reGeocodeTimeout = 10;
//    
//    [self.locationManager startUpdatingLocation];
//    
//    self.mapView.zoomLevel = 14;
//    
//    self.annotationArray = [NSMutableArray array];
    
    
    [_mainTableView registerNib:[UINib nibWithNibName:@"XuanZeDiDianTableViewCell" bundle:nil] forCellReuseIdentifier:@"XuanZeDiDianTableViewCell"];
    _mainTableView.rowHeight = UITableViewAutomaticDimension;
    _mainTableView.estimatedRowHeight = 77;
    
    _bottomSpace.constant = ScreenBottom + 15;
    _bottomViewHeight.constant = 328+ScreenBottom;
    
    [self.searchTf addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
    
}

- (void)textFieldChange:(UITextField *)tf{
//    if(tf.text.length == 0){
//        dataSource = [NSMutableArray arrayWithArray:orignArray];
//    }else{
//        dataSource = [NSMutableArray array];
//        for (BMKPoiInfo *info in orignArray) {
//            if([info.name containsString:tf.text]){
//                [dataSource addObject:info];
//            }
//        }
//    }
    [_mainTableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    XuanZeDiDianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XuanZeDiDianTableViewCell"];
    //    AMapPOI *poiResult = self.arrKeyList[indexPath.row];
    //    cell.nameLabel.text = poiResult.name;
    //    cell.addressLabel.text = poiResult.address;
    //    if(currentIndex == indexPath.row){
    //        cell.rightSpace.constant = 40;
    //        cell.xuanZhongImage.hidden = NO;
    //    }else{
    //        cell.rightSpace.constant = 15;
    //        cell.xuanZhongImage.hidden = YES;
    //    }
//    BMKPoiInfo *info = dataSource[indexPath.row];
//    cell.nameLabel.text = info.name;
//    cell.addressLabel.text = info.address;
//   
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //    currentIndex = indexPath.row;
    [_mainTableView reloadData];
}


//#pragma mark - LocationDelegate 百度地图代理
///**
// *定位失败后，会调用此函数
// *@param error 错误号
// */
//- (void)didFailToLocateUserWithError:(NSError *)error
//{
//    NSLog(@"地图定位失败======%@",error);
//}
//
////处理位置坐标更新
//- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
//{
//    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,
//          userLocation.location.coordinate.longitude);
//    if ((userLocation.location.coordinate.latitude != 0 || userLocation.location.coordinate.longitude != 0))
//    {
//        NSString *latitude = [NSString stringWithFormat:@"%f",userLocation.location.coordinate.latitude];
//        NSString *longitude = [NSString stringWithFormat:@"%f",userLocation.location.coordinate.longitude];
//        NSLog(@"didUpdateUserLocation lat %@,long %@",latitude,
//              longitude);
//        [self reverseGeoCodeWithLatitude:userLocation.location.coordinate];
//    }else{
//        NSLog(@"失败");
//    }
//}
//
////检索对象
//- (BMKGeoCodeSearch *)geocodeSearch
//{
//    if (!_geocodeSearch)
//    {
//        _geocodeSearch = [[BMKGeoCodeSearch alloc] init];
//        _geocodeSearch.delegate = self;
//    }
//    return _geocodeSearch;
//}
//
//#pragma mark ----反向地理编码
//- (void)reverseGeoCodeWithLatitude:(CLLocationCoordinate2D)coor{
//    
//    BMKReverseGeoCodeSearchOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeSearchOption alloc] init];
//    reverseGeocodeSearchOption.location = coor;
//    BOOL flag = [self.geocodeSearch reverseGeoCode:reverseGeocodeSearchOption];;
//    if (flag)
//    {
//        NSLog(@"反地理编码成功");
//    }
//    else
//    {
//        NSLog(@"反地理编码失败");
//    }
//}
//
//
////发送成功,百度将会返回东西给你
//-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher
//                          result:(BMKReverseGeoCodeSearchResult *)result
//                       errorCode:(BMKSearchErrorCode)error{
//    if (error == BMK_SEARCH_NO_ERROR) {
//        NSString *address = result.address;  //地址名称
//        NSString *sematicDescription = result.sematicDescription;  //结合当前位置POI的语义化结果描述
//        NSString *businessCircle = result.businessCircle;  //商圈名称
//        BMKAddressComponent *addressDetail = result.addressDetail;  //层次化地址信息
//        NSArray *poiList = result.poiList;  //地址周边POI信息，成员类型为BMKPoiInfo
//        for (BMKPoiInfo *info in poiList) {
//            NSLog(@"%@==%@",info.name,info.address);
//        }
//        orignArray = poiList;
//        dataSource = [NSMutableArray arrayWithArray:poiList];
//        [_mainTableView reloadData];
////        NSLog(@"我的位置在 %@ 结合当前位置POI的语义化结果描述:%@ 商圈名称:%@ 层次化地址信息:%@ 地址周边POI信息，成员类型为BMKPoiInfo:%@",address,sematicDescription,businessCircle,addressDetail,poiList);
//        
//    }
//}
//
//
//
//
//#pragma mark 数据显示
//- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
//{
//    //这里的判断你可把它看做和UItableVIew判断一样(先去看是不是我的类型)
//    //这里我的位置使用的是自定义大头针,判断是不是我的我的位置
//    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
//        
//        BMKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"userLocation"];
//        
//        if(annotationView == nil){
//            
//            annotationView = [[BMKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"UserLocation"];
//        }
//        
//        annotationView.image = [UIImage imageNamed:@"地图我的当前位置"];
//        return annotationView;
//    }
//    return nil;
//}
//
//
//- (void)BMKLocationManager:(BMKLocationManager *)manager didUpdateHeading:(CLHeading *)heading {
//    if (!heading) {
//        return;
//    }
//    if (!self.userLocation) {
//        self.userLocation = [[BMKUserLocation alloc] init];
//    }
//    self.userLocation.heading = heading;
//    [self.mapView updateLocationData:self.userLocation];
//}
//
//
//// 定位SDK中，位置变更的回调
//- (void)BMKLocationManager:(BMKLocationManager *)manager didUpdateLocation:(BMKLocation *)location orError:(NSError *)error {
//    if (error) {
//        NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
//    }
//    if (!location) {
//        return;
//    }
//    if (!self.userLocation) {
//        self.userLocation = [[BMKUserLocation alloc] init];
//    }
//    self.userLocation.location = location.location;
//    [self.mapView updateLocationData:self.userLocation];
//    
//    [self reverseGeoCodeWithLatitude:location.location.coordinate];
//    
//    [self.locationManager stopUpdatingLocation];
//    
//    MyAnnotation* userAnnotation = [[MyAnnotation alloc]init];
//    
//    userAnnotation.coordinate = location.location.coordinate;
//    userAnnotation.type = @0;
//    
//    [_mapView addAnnotation:userAnnotation];
//}
//
//-(void)viewWillAppear:(BOOL)animated
//{
//    [super viewWillAppear:animated];
//    [_mapView viewWillAppear];
//}
//-(void)viewWillDisappear:(BOOL)animated
//{
//    [super viewWillDisappear:animated];
//    [_mapView viewWillDisappear];
//}
//回到我原先的位置
- (IBAction)huiDao:(UIButton *)sender {
//    [self.mapView setCenterCoordinate:self.userLocation.location.coordinate animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
